home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / debugnub / CedarCirioNubProcs.c < prev    next >
C/C++ Source or Header  |  1992-04-16  |  9KB  |  309 lines

  1. /* begincopyright
  2.   Copyright (c) 1988-1992 Xerox Corporation. All rights reserved.
  3.   Use and copying of this software and preparation of derivative works based
  4.   upon this software are permitted. Any distribution of this software or
  5.   derivative works must comply with all applicable United States export
  6.   control laws. This software is made available AS IS, and Xerox Corporation
  7.   makes no warranty about the software, its performance or its conformity to
  8.   any specification. Any person obtaining a copy of this software is requested
  9.   to send their name and post office or electronic mail address to:
  10.     PCR Coordinator
  11.     Xerox PARC
  12.     3333 Coyote Hill Rd.
  13.     Palo Alto, CA 94304
  14.   endcopyright */
  15.  
  16. /*
  17.  * CedarCirioNubProcs.c
  18.  *
  19.  * A collection of procs to examine Cedar Typecodes
  20.  *
  21.  * Demers, March 3, 1992 5:09:57 pm PST
  22.  */
  23.  
  24. #define CCNP_DEBUG 1
  25. #define DYNAMIC_C_LOOKUP 0
  26.  
  27.  
  28. /* #include "xr/CirioNubProtocol.h" */
  29. #include "xr/CirioNubMarshall.h"
  30. #include "xr/CedarCirioNubProcs.h"
  31. /* #include "xr/CirioNubEnvironment.h" */
  32. #include "xr/CirioNubInstall.h"
  33.  
  34. #if DYNAMIC_C_LOOKUP
  35. #   include "xr/IncrementalLoad.h"
  36. #endif
  37.  
  38. #if CCNP_DEBUG
  39. #   include "xr/ThreadsMsg.h" /* for XR_ConsoleMsg debug msgs */
  40. #endif
  41.  
  42. /*
  43.  * The following two utilities are stolen directly from Interp.c ...
  44.  *   call from thread only.
  45.  */
  46.  
  47. #if DYNAMIC_C_LOOKUP
  48. int
  49. CedarCirioNubLookupCProc(name, valp)
  50.     char *name;
  51.     unsigned *valp;
  52. {
  53.     XR_ILSymEntry ilse;
  54.     char *altText;
  55.  
  56.     ilse = XR_ILGetMatchingSymEntryByName(
  57.             NIL, name, TRUE, WANT_ALL_TYPES, IGNORE_INTERNAL, 0 );
  58.     if( ilse == NIL ) {
  59.         ilse = XR_ILGetMatchingSymEntryByName(
  60.                 NIL, name, TRUE, WANT_ALL_TYPES, IGNORE_NONE, 0 );
  61.     }
  62.     if( (ilse == NIL) && (name[0] != '_') ) {
  63.         altText = (char *)XR_malloc(2+strlen(name));
  64.         altText[0] = '_'; (void)strcpy(&(altText[1]), name);
  65.         ilse = XR_ILGetMatchingSymEntryByName(
  66.                 NIL, altText, TRUE, WANT_ALL_TYPES, IGNORE_INTERNAL, 0 );
  67.         if( ilse == NIL ) {
  68.             ilse = XR_ILGetMatchingSymEntryByName(
  69.                 NIL, altText, TRUE, WANT_ALL_TYPES, IGNORE_NONE, 0 );
  70.         }
  71.     }
  72.     if( ilse == NIL ) {
  73.         return (-1);
  74.     }
  75.     *valp = ((unsigned)(ilse->ilse_value));
  76.     return 0;
  77. }
  78. #endif
  79.  
  80.  
  81. int
  82. CedarCirioNubLookupCedarProc(interfaceName, procName, procp)
  83.     char *interfaceName;
  84.     char *procName;
  85.     XR_MesaProc *procp;
  86. {
  87.     static XR_MesaProc ((*procFromNamedInterface)()) = NIL;
  88.     int ans;
  89.     char *tailP, *dotP;
  90.     XR_MesaProc cedarProcValue;
  91.  
  92. #   if CCNP_DEBUG
  93.         XR_ConsoleMsg("CirioNubBinding to %s %s ... ", interfaceName, procName);
  94. #   endif
  95.     if( (interfaceName == NIL) || (procName == NIL) ) return (-1);
  96. #   if DYNAMIC_C_LOOKUP
  97.         if( procFromNamedInterface == NIL ) {
  98.             ans = CedarCirioNubLookupCProc( "XR_ProcFromNamedInterface",
  99.                     &procFromNamedInterface );
  100.             if( ans < 0 ) return ans;
  101.         }
  102. #   else
  103.         {
  104.             extern XR_MesaProc XR_ProcFromNamedInterface();
  105.             procFromNamedInterface = XR_ProcFromNamedInterface;
  106.         }
  107. #   endif
  108.     cedarProcValue = (*procFromNamedInterface)(interfaceName, procName, NIL, 0);
  109. #   if CCNP_DEBUG
  110.         XR_ConsoleMsg("result 0x%x ", cedarProcValue);
  111.         if( cedarProcValue ) XR_ConsoleMsg( "(0x%x 0x%x)",
  112.                 cedarProcValue->mp_proc, cedarProcValue->mp_x );
  113.         XR_ConsoleMsg("\n");
  114. #   endif
  115.     if( cedarProcValue == NIL ) {
  116.         return(-1);
  117.     }
  118.     (*procp) = cedarProcValue;
  119.     return 0;
  120. }
  121.  
  122. /*
  123.  * Binding to MesaLoadState ...
  124.  *
  125.  *   This initialization must be called from a thread before the debug nub
  126.  *     starts running in its slave IOP.
  127.  */
  128.  
  129. static XR_MesaProc mpGetTypestring = NIL;
  130. static XR_MesaProc mpGetTypecode = NIL;
  131. static XR_MesaProc mpGetConcreteTypecode = NIL;
  132.  
  133. static void
  134. CedarCirioNubBindToLoadStateProcs()
  135. {
  136.     (void)CedarCirioNubLookupCedarProc(
  137.                 "MesaLoadStateBackdoor", "UnmonitoredTypeStringFromType",
  138.                 &mpGetTypestring );
  139.     (void)CedarCirioNubLookupCedarProc(
  140.                 "MesaLoadStateBackdoor", "UnmonitoredFindTypeFromTypeString",
  141.                 &mpGetTypecode );
  142.     (void)CedarCirioNubLookupCedarProc(
  143.                 "MesaLoadState", "ConcreteTypeFromAbstractType",
  144.                 &mpGetConcreteTypecode );
  145. }
  146.  
  147.  
  148.  
  149. /*
  150.  * Exported Cirio Nub Procs ...
  151.  */
  152.  
  153. #define MESA_STRING_MAXLEN    4000
  154.  
  155. typedef struct MesaStringRep {
  156.     unsigned short ms_len;
  157.     unsigned short ms_maxLen;
  158.     char ms_data[MESA_STRING_MAXLEN];
  159. } * MesaString;
  160.  
  161.  
  162. CirioNubRetCode
  163. CedarCirioNubServeGetTypestring(argc, args)
  164.     int argc;
  165.     unsigned *args;
  166. {
  167.     XR_MesaProc mp = mpGetTypestring;
  168.     int ans;
  169.     CirioNubRetCode rc;
  170.     struct CirioNubCedarTypeCodeRep tc;
  171.     MesaString ms;
  172.  
  173. #   if CCNP_DEBUG
  174.         XR_ConsoleMsg("CirioNub GetTypestring argc %d\n", argc);
  175. #   endif
  176.     if( argc != 1 ) return( cnrc_badArgs );
  177.     tc.typeCode = (unsigned long)(args[0]);
  178.     
  179.     if( mp == NIL ) return cnrc_noProc;
  180.     ms = (MesaString) ((*(mp->mp_proc))(tc.typeCode, mp));
  181.     if( ms == NIL ) {
  182. #       if CCNP_DEBUG
  183.             XR_ConsoleMsg("GetTypestring fails ms == NIL\n");
  184. #       endif
  185.         return cnrc_badArgs; /* ??? */
  186.     }
  187. #   if CCNP_DEBUG
  188.         XR_ConsoleMsg("GetTypestring res len %d\n", ms->ms_len);
  189. #   endif
  190.     if( (rc = CirioNubPutBlock8(ms->ms_data, ms->ms_len)) != cnrc_ok )
  191.         return rc;
  192.     return cnrc_ok;
  193. }
  194.  
  195.  
  196. CirioNubRetCode
  197. CedarCirioNubServeGetTypecode(argc, args)
  198.     int argc;
  199.     unsigned *args;
  200. {
  201.     int ans, len;
  202.     CirioNubRetCode rc;
  203.     XR_MesaProc mp = mpGetTypecode;
  204.     struct {
  205.         long fnd; 
  206.         struct CirioNubCedarTypeCodeRep tc;
  207.     } resultRec;
  208.     struct MesaStringRep ms;
  209.  
  210. #   if CCNP_DEBUG
  211.         XR_ConsoleMsg("CirioNub GetTypecode argc %d ", argc);
  212.         if( argc >= 1 ) XR_ConsoleMsg("len %d", (int)(args[0]));
  213.         XR_ConsoleMsg("\n");
  214. #   endif
  215.  
  216.     if( argc != 2 ) return cnrc_badArgs;
  217.     len = (int)(args[0]);
  218.     if( len > MESA_STRING_MAXLEN ) return cnrc_badArgs;
  219.     ms.ms_len = len;
  220.     ms.ms_maxLen = MESA_STRING_MAXLEN;
  221.     bcopy( (char *)(args[1]), ms.ms_data, len);
  222.  
  223.     if( mp == NIL ) return cnrc_noProc;
  224.     (*(mp->mp_proc))(&resultRec, &ms, mp);
  225. #   if CCNP_DEBUG
  226.         XR_ConsoleMsg("CirioNub GetTypecode res %d 0x%x\n",
  227.                 resultRec.fnd, resultRec.tc.typeCode );
  228. #   endif
  229.     if( (rc = CirioNubPutCard32(resultRec.fnd)) != cnrc_ok ) return rc;
  230.     if( (rc = CirioNubPutCard32(resultRec.tc.typeCode)) != cnrc_ok ) return rc;
  231.     return cnrc_ok;
  232. }
  233.  
  234.  
  235.  
  236. CirioNubRetCode
  237. CedarCirioNubServeGetConcreteTypecode(argc, args)
  238.     int argc;
  239.     unsigned *args;
  240. {
  241.     XR_MesaProc mp = mpGetConcreteTypecode;
  242.     int ans;
  243.     CirioNubRetCode rc;
  244.     struct CirioNubCedarTypeCodeRep abs;
  245.     struct CirioNubCedarTypeCodeRep conc;
  246.  
  247. #   if CCNP_DEBUG
  248.         XR_ConsoleMsg("CirioNub GetConcrete argc %d ", argc);
  249.         if( argc >= 1 ) XR_ConsoleMsg("arg 0x%x", args[0]);
  250.         XR_ConsoleMsg("\n");
  251. #   endif
  252.     if( argc != 1 ) return cnrc_badArgs;
  253.     abs.typeCode = (unsigned long)(args[0]);
  254.  
  255.     if( mp == NIL ) return cnrc_noProc;
  256.     conc.typeCode = (*(mp->mp_proc))(abs.typeCode, mp);
  257. #   if CCNP_DEBUG
  258.         XR_ConsoleMsg("GetConcrete res 0x%x\n", conc.typeCode);
  259. #   endif
  260.  
  261.     if( (rc = CirioNubPutCard32(conc.typeCode)) != cnrc_ok ) return rc;
  262.     return cnrc_ok;
  263. }
  264.  
  265.  
  266. static CirioNubRetCode
  267. CedarCirioNubServeNull(argc, args)
  268.     int argc;
  269.     unsigned *args;
  270. {
  271.     unsigned v;
  272.     CirioNubRetCode rc;
  273.  
  274.     v = ((argc >= 1) ? args[0] : CEDAR_CIRIO_NUB_PROCS_VERSION); 
  275.     if( v < CEDAR_CIRIO_NUB_PROCS_LOW_VERSION ) {
  276.         v = CEDAR_CIRIO_NUB_PROCS_LOW_VERSION;
  277.     } else if( v > CEDAR_CIRIO_NUB_PROCS_VERSION ) {
  278.         v = CEDAR_CIRIO_NUB_PROCS_VERSION;
  279.     }
  280.     if( (rc = CirioNubPutCard32(v)) != cnrc_ok ) return rc;
  281.     return cnrc_ok;
  282. }
  283.  
  284.  
  285. int
  286. XR_run_CedarCirioNub()
  287. {
  288.     CirioNubHandle h;
  289.  
  290.     if( (h = CirioNubGetDefaultHandle(0, 0)) == NIL ) return (-1);
  291.  
  292.     CedarCirioNubBindToLoadStateProcs();
  293.  
  294.     (void)CirioNubRegisterCProc(h,
  295.         CedarCirioNubProcID_Null,
  296.         CedarCirioNubServeNull);
  297.     (void)CirioNubRegisterCProc(h,
  298.         CedarCirioNubProcID_GetTypestring,
  299.         CedarCirioNubServeGetTypestring);
  300.     (void)CirioNubRegisterCProc(h,
  301.         CedarCirioNubProcID_GetTypecode,
  302.         CedarCirioNubServeGetTypecode);
  303.     (void)CirioNubRegisterCProc(h,
  304.         CedarCirioNubProcID_GetConcreteTypecode,
  305.         CedarCirioNubServeGetConcreteTypecode);
  306.  
  307.     return 0;
  308. }
  309.